class Solution {
    public int uniquePaths(int m, int n) {
        if (m == 1 || n == 1) return 1;
        int result = 0;
        int[][] index = new int[m+1][n+1];
        for (int i = 1; i < m+1; i++){
            for (int j = 1; j <n+1; j++){
                if(i == 1 || j == 1) {
                    index[i][j] = 1;
                    continue;
                }
                index[i][j] = index[i-1][j] + index[i][j-1];
            }
        }
        return index[m][n];
    }
}